import requests
import os
import re
import time
from bs4 import BeautifulSoup

URL = 'https://morvanzhou.github.io/tutorials/data-manipulation/scraping/5-01-selenium/'
aa = "https://morvanzhou.github.io"
html = requests.get(URL).text
# print(html)
soup = BeautifulSoup(html, features='lxml')

imgs = soup.find_all('img')
os.makedirs('./img/', exist_ok=True)
for img in imgs:
    url = aa+img['src']
    r = requests.get(url, stream=True)
    image_name = url.split('/')[-1]  ########################
    with open('./img/%s' % image_name, 'wb+') as f:
        for chunk in r.iter_content(chunk_size=128):
            f.write(chunk)
    print('Saved %s' % image_name)
